﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.sprite;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using imaginecup.util;
using Imaginecup.util.input;

namespace Imaginecup.gameState.water.controller.phone
{
    public class RightController:ITouchProcess
    {
        ISprite m_Sprite;
        EntityInfo info;

        public RightController()
        {
            NormalSprite right = new NormalSprite();
            right.SetTextureName("water_right_point");

            m_Sprite = right;
            info = new EntityInfo(567,250,232,231);
        }
//         public bool TouchBegin(Vector2 currentTouchPosition)
//         {
//             Vector2 direction = outerPosition - currentTouchPosition;
// 
//             rate = direction.Length() / (outerTexture.Width * 0.5f);
// 
//             //누른상태에서 범위를 벗어났을 경우 경계로 돌려놔야한다.
//             if ((0.0f <= rate) &&
//                 (1.0f >= rate))
//             {
//                 m_bFlagIn = true;
//                 //innerPosition = currentTouchPosition;
// 
//                 if (DEADZONE_RATE <= rate)
//                 {
//                     touchScreenState.Direction = direction;
// 
//                     returnTouchDirection = direction;
// 
//                     Vector2 imsi = touchScreenState.Direction;
// 
//                     returnTouchRotation = (float)Math.Atan2(imsi.Y, imsi.X);
// 
//                     if (returnTouchDirection != Vector2.Zero)
//                     {
//                         returnOldTouchDirection = returnTouchDirection;
//                         returnOldTouchRotation = returnTouchRotation;
//                     }
//                     return true;
//                 }
//             }
        public float GetRotation()
        {
            const float DEADZONE_RATE = 0.2f;
            float rotation = 0.0f;

            Vector2 direction = info.GetEntityCenter() - info.GetEntityCenter();//터치한 좌표를 넣어야함

            float rate = direction.Length() / (info.mSize.X * 0.5f);

            if ((0.0f <= rate) && (1.0f >= rate))
            {
                //현재 선택된 좌표는 infoIn의 좌표로 대입해야함
                if (DEADZONE_RATE <= rate)
                {
                    rotation = (float)Math.Atan2(direction.Y, direction.X);
                }
            }
            return rotation;
        }

        public void Update(GameTime gameTime)
        {

        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            m_Sprite.Draw(spriteBatch, info);
        }

        public void TouchBegan(Microsoft.Xna.Framework.Input.Touch.TouchLocation touch)
        {
            throw new NotImplementedException();
        }

        public void TouchMove(Microsoft.Xna.Framework.Input.Touch.TouchLocation touch)
        {
            throw new NotImplementedException();
        }

        public void TouchEnd(Microsoft.Xna.Framework.Input.Touch.TouchLocation touch)
        {
            throw new NotImplementedException();
        }

        internal bool CheckLocation(Microsoft.Xna.Framework.Input.Touch.TouchLocation touch)
        {
            return false;
        }
    }
}
